import 'package:efood_multivendor/data/api/api_client.dart';
import 'package:efood_multivendor/util/app_constants.dart';

import 'package:get/get_connect/http/src/response/response.dart';

import '../model/body/checkout_body_model.dart';

class RestaurantRepo {
  final ApiClient apiClient;
  RestaurantRepo({required this.apiClient});

  Future<Response> getRestaurantList(
      String offset, String filterBy, String? sort, String priceRange) async {
    if (sort != null) {
      String uriToCall =
          '${AppConstants.RESTAURANT_URI}/$filterBy?offset=$offset&limit=10&sort=$sort&price_range=$priceRange';
      return await apiClient.getData(
          '${AppConstants.RESTAURANT_URI}/$filterBy?offset=$offset&limit=10&sort=$sort&price_range=$priceRange');
    } else {
      return await apiClient.getData(
          '${AppConstants.RESTAURANT_URI}/$filterBy?offset=$offset&limit=10');
    }
  }

  Future<Response> checkout(CheckoutBody checkoutBody) async {
    return await apiClient.postData(
        AppConstants.CHECKOUT_URI, checkoutBody.toJson());
  }

  Future<Response> getPopularRestaurantList(String type) async {
    return await apiClient
        .getData('${AppConstants.POPULAR_RESTAURANT_URI}?type=$type');
  }

  Future<Response> getLatestRestaurantList(String type) async {
    return await apiClient
        .getData('${AppConstants.LATEST_RESTAURANT_URI}?type=$type');
  }

  Future<Response> getSuggestedKeywords(
      String keyword, String referer, String restaurant_id) async {
    return await apiClient.getData('${AppConstants.SUGGESTED_KEYWORD_URI}' +
        '$keyword' +
        '&referer=$referer&restaurant_id=$restaurant_id');
  }

  Future<Response> getRestaurantDetails(
      String restaurantID, String referer) async {
    return await apiClient.getData(
        '${AppConstants.RESTAURANT_DETAILS_URI}$restaurantID?referer=$referer');
  }

  Future<Response> getRestaurantProductList(
      int restaurantID, int offset, int categoryID, String type) async {
    String testing =
        "${AppConstants.RESTAURANT_PRODUCT_URI}?restaurant_id=$restaurantID&category_id=$categoryID&offset=$offset&limit=10&type=$type";
    return await apiClient.getData(
      '${AppConstants.RESTAURANT_PRODUCT_URI}?restaurant_id=$restaurantID&category_id=$categoryID&offset=$offset&limit=10&type=$type',
    );
  }

  Future<Response> getRestaurantReviewList(String restaurantID) async {
    return await apiClient.getData(
        '${AppConstants.RESTAURANT_REVIEW_URI}?restaurant_id=$restaurantID');
  }

  Future<Response> getSearchData(
      String query, String restaurantID, int offset) async {
    return await apiClient.getData(
      '${AppConstants.SEARCH_URI}products/search?name=$query&restaurant_id=$restaurantID&offset=$offset&limit=10',
    );
  }
}
